
\section{Appendix}
\subsection{How to run the program}

Extract the files from ai08-11.tar.gz with:

tar -zxvf ai08-11.tar.gz

cd ai08-11/

Then run the program with:

java -jar dist/AI.jar

Have fun!

\subsection{Rule file}

\footnotesize
	
\begin{verbatim}
# -----------= Lexicon =--------------- ;


# ---- Nouns ---- ;

INGR["apple", "apricot", "ash",
    "banana", "bay", "beef", "bouillon", "bread", "butter",
    "cabbage", "calvado", "cantaloupe", "carrot", "catsup", "cayenne", "challah",
    "chicken", "chili", "cinnamon", "cod", "corn", "cracker", "cream", "crumb",
    "cucumber", "cumin", "currnat",
    "dill",
    "egg",
    "fish", "flour", "fruit",
    "garlic", "gin", "ginger", "graham", "grape",
    "honey",
    "juice",
    "kiwi",
    "lattice", "leaf", "lemon", "lime", "lutfisk",
    "margarine", "meat", "milk", "molass", "moose", "mushroom",
    "nutmeg",
    "oak", "oil", "onion", "orange",
    "paprika", "parsley", "pasta", "peanut", "pear", "pepper", "peppercorn", "pesto",
    "pineaple", "pineapple", "pork", "potato", "prune",
    "raisin", "rotelle", "ruccola",
    "salmon", "salt", "sauce", "soda", "squash", "sugar",
    "tapioca", "thyme", "tomato",
    "vanilla",
    "water",
    "youghurt"];

INGR:INGRPL[(INGR,INGR[-1] != x & INGR[-1] != s & INGR[-1] != y & INGR[-1] != o & INGR[-1] != h ? INGR + s ),
            (INGR,INGR[-1] == x | INGR[-1] == s | INGR[-1] == o | INGR[-1] == h ? INGR + es ),
            (INGR,INGR[-1] == y ? INGR[0..-2] + ies )];

SINGLEWORDMEALS["meatballs","braunburger","cheesecake", "hamburger", "lutfisk", "raggmunk",];

STARTER:STARTERS[("starter", "starters")];

REGN[
"age", "air", "anger", "animal", "answer", "apple", "area", "arm", "art", "atom",
"baby", "back", "ball", "band", "bank", "bar", "base", "bat", "bear", "beauty",
"bed", "bell", "bird", "birthday", "bit", "block", "blood", "blow", "board", 
"boat", "body", "bone", "book", "bottom", "box", "boy", "branch", "bread", "break", "brother",
"cake", "call", "camp", "capital", "captain", "car", "card", "care", "case", "cat",
"cause", "cell", "cent", "century", "chair", "chance", "change", "character",
"chick", "chicken", "chief", "child", "children", "chord", "christmas", "circle", "city", 
"class", "climb", "clock", "cloud", "coast", "coat", "cold", "colony", "color", "column",
"company", "condition", "consonant", "continent", "cookie", "copy", "corn", "cost", "cotton",
"country", "course", "cover", "cow", "crop", "cross", "crowd", "cry", "current", "cut", 
"dad", "dance", "danger", "day", "dead", "deal", "death", "decimal", "degree",
"design", "dictionary", "dish", "division", "doctor", "dog", "doll", "dollar", 
"door", "double", "draw", "dream", "dress", "drink", "drive", "drop", "duck",
"ear", "earth", "ease", "east", "edge", "effect", "egg", "eight", "element",
"end", "enemy", "energy", "eye",
"farm", "farmer", "father", "feet", "fire", "fish", "floor", "flower", "fork", "fox", "fungus",
"game", "garden", "girl", "good-bye", "grass", "ground",
"hand", "head", "hill", "hole", "home", "horse", "house",
"kitty",
"leg", "letter", "lot",
"man", "meal", "men", "mind", "money", "morning", "moth",  "mother",
"name", "nest", "night",
"pan", "paper", "party", "people", "picture", "pig", "plate",
"rabbit", "rain", "ring", "robin",
"santa", "school", "seed", "sheep", "shoe", "sister", "snow", "something",
"song", "soup", "soupe", "spoon", "squirrel", "stew", "stick", "street", "sun", "sweater",
"table", "thing", "time", "toast", "top", "toy", "tree",
"watch", "water", "way", "weather", "wind", "window"];

REGN:REGNPL[(REGN,REGN[-1] != x & REGN[-1] != s & REGN[-1] != y & REGN[-1] != o ? REGN + s ),
        (REGN,REGN[-1] == x | REGN[-1] == s | REGN[-1] == o ? REGN + es ),
        (REGN,REGN[-1] == y ? REGN[0..-2] + ies )];

ALRG:INGR[("lactose", "milk")];

# Just a bunch of irregular nouns. This list was found on the Internet. ;
IRREGN:IRREGNPL[("addendum", "addenda"),
("alga", "algae"),
("alumna", "alumnae"),
("alumnus", "alumni"),
("analysis", "analyses"),
("antenna", "antennas"),
("antenna", "antennae"),
("apparatus", "apparatuses"),
("appendix", "appendices"),
("appendix", "appendixes"),
("axis", "axes"),
("bacillus", "bacilli"),
("bacterium", "bacteria"),
("basis", "bases"),
("beau", "beaux"),
("bison", "bison"),
("buffalo", "buffalos"),
("buffalo", "buffaloes"),
("bureau", "bureaus"),
("bus", "busses"),
("bus", "buses"),
("cactus", "cactuses"),
("cactus", "cacti"),
("calf", "calves"),
("child", "children"),
("corps", "corps"),
("corpus", "corpora"),
("corpus", "corpuses"),
("crisis", "crises"),
("criterion", "criteria"),
("curriculum", "curricula"),
("datum", "data"),
("deer", "deer"),
("die", "dice"),
("dwarf", "dwarfs"),
("dwarf", "dwarves"),
("diagnosis", "diagnoses"),
("echo", "echoes"),
("elf", "elves"),
("ellipsis", "ellipses"),
("embargo", "embargoes"),
("emphasis", "emphases"),
("erratum", "errata"),
("fireman", "firemen"),
("focus", "focuses"),
("foot", "feet"),
("formula", "formulas"),
("fungus", "fungi"),
("fungus", "funguses"),
("genus", "genera"),
("goose", "geese"),
("half", "halves"),
("hero", "heroes"),
("hippopotamus", "hippopotami"),
("hippopotamus", "hippopotamuses"),
("hoof", "hoofs"),
("hoof", "hooves"),
("hypothesis", "hypotheses"),
("index", "indices"),
("index", "indexes"),
("knife", "knives"),
("leaf", "leaves"),
("life", "lives"),
("loaf", "loaves"),
("louse", "lice"),
("man", "men"),
("matrix", "matrices"),
("means", "means"),
("medium", "media"),
("memorandum", "memoranda"),
("millennium", "millenniums"),
("millennium", "milennia"),
("mosquito", "mosquitoes"),
("mouse", "mice"),
("nebula", "nebulae"),
("nebula", "nebulas"),
("neurosis", "neuroses"),
("nucleus", "nuclei"),
("oasis", "oases"),
("octopus", "octopi"),
("octopus", "octopuses"),
("ovum", "ova"),
("ox", "oxen"),
("paralysis", "paralyses"),
("parenthesis", "parentheses"),
("person", "people"),
("phenomenon", "phenomena"),
("radius", "radii"),
("radius ", "radiuses"),
("scarf", "scarfs"),
("scarf", "scarves"),
("self", "selves"),
("series", "series"),
("sheep", "sheep"),
("shelf", "shelves"),
("scissors", "scissors"),
("species", "species"),
("stimulus", "stimuli"),
("stratum", "strata"),
("syllabus", "syllabi"),
("syllabus", "syllabuses"),
("symposium", "symposia"),
("symposium", "symposiums"),
("synthesis", "syntheses"),
("synopsis", "synopses"),
("tableau", "tableaux"),
("that", "those"),
("thesis", "theses"),
("thief", "thieves"),
("this", "these"),
("tooth", "teeth"),
("torpedo", "torpedoes"),
("vertebra", "vertebrae"),
("veto", "vetoes"),
("vita", "vitae"),
("watch", "watches"),
("wife", "wives"),
("wolf", "wolves"),
("woman", "women"),
("zero", "zeros"),
("zero", "zeroes")];

POSREGN:POSREGPL[("tolerance", "tolerances"), ("favorite", "favorites")];

NEGREGN:NEGREGNPL[("intolerance", "intolerances"), ("allergy", "allergies")];


# ---- Verbs ---- ;

POSRV["accept", "add", "agree", "allow", 
"contain", "desire", "encourage", "enjoy", "have", "include", "like", "love", 
"require", "want", "give", "get"];


POSRV:POSRVCUR:POSRVIMP[(POSRV, POSRV[-1] == e ? POSRV[0..-2] + ing, POSRV + d),
                        (POSRV, POSRV[-1] != e ? POSRV + ing, POSRV[-1] != y ? POSRV + ed),
                        (POSRV, POSRV[-1] != e ? POSRV + ing, POSRV[-1] == y ? POSRV[0..-2] + ied)];

NEGRV["avoid", "dislike", "remove", "hate"];

NEGRV:NEGRVCUR:NEGRVIMP[(NEGRV, NEGRV[-1] == e ? NEGRV[0..-2] + ing, NEGRV + d),
                        (NEGRV, NEGRV[-1] != e ? NEGRV + ing, NEGRV[-1] != y ? NEGRV + ed),
                        (NEGRV, NEGRV[-1] != e ? NEGRV + ing, NEGRV[-1] == y ? NEGRV[0..-2] + ied)];


RV["account", "achieve", "act", "admit", "affect", "afford", "aim", 
"answer", "appear", "apply", "argue", "arrange", "arrive", "ask", "attack",
"base", "beat", "believe", "belong", "break", "build", "burn", "buy", 
"call", "can", "care", "carry", "cause", "change", "charge", "check", 
"choose", "claim", "clean", "clear", "climb", "close", "collect", "commit", 
"compare", "complain", "complete", "concern", "confirm", "connect", "consider", 
"consist", "contact", "continue", "contribute", "control", "cook", "copy", 
"correct", "cost", "count", "cover", "create", "cross", "cry", "cut", 
"damage", "dance", "deal", "decide", "deliver", "demand", "deny", "depend", 
"describe", "design", "destroy", "develop", "die", "disappear", "discover", 
"discuss", "divide", "draw", "dress", "drink", "drive", "drop", 
"enable", "examine", "exist", "expect", "experience", "explain", "express", "extend", 
"face", "fail", "fall", "fasten", "feed", "feel", "fight", "fill", "find", "finish", 
"fit", "fly", "fold", "follow", "force", "forget", "forgive", "form", "found", 
"gain", "grow", 
"handle", "happen", "head", "hear", "help", "hide", "hit", "hold", "hope", "hurt", 
"identify", "imagine", "improve", "increase", "indicate", "influence", 
"inform", "intend", "introduce", "invite", "involve", 
"join", "jump", 
"keep", "kick", "kill", "knock", "know", 
"last", "laugh", "lax", "lay", "lead", "learn", "leave", "lend", "let", "lie",
"limit", "link", "listen", "live", "look", "lose", 
"make", "manage", "mark", "matter", "may", "mean", "measure", "meet", "mention", 
"might", "mind", "miss", "move", "must", 
"need", "notice", 
"obtain", "occur", "offer", "open", "order", "ought", "own", 
"pass", "pay", "perform", "pick", "place", "plan", "play", "point", "prefer", 
"prepare", "present", "press", "prevent", "produce", "promise", "protect", "prove", 
"provide", "publish", "pull", "push", "put", 
"raise", "reach", "read", "realize", "receive", "recognize", "record", "reduce", 
"refer", "reflect", "refuse", "regard", "relate", "release", "remain", "remember", 
"repeat", "replace", "reply", "report", "represent", "rest", 
"result", "return", "reveal", "ring", "rise", "roll", "run", 
"save", "say", "see", "seem", "sell", "send", "separate", "serve", "set", "settle", 
"shake", "shall", "share", "shoot", "should", "shout", "show", "shut", "sing", 
"sit", "sleep", "smile", "sort", "sound", "speak", "stand", "start", "state", 
"stay", "stick", "stop", "study", "succeed", "suffer", "suggest", "suit", "supply", 
"support", "suppose", "survive", 
"take", "talk", "tell", "tend", "test", "thank", "think", "throw", 
"touch", "train", "travel", "treat", "try", "turn", 
"understand", "use", 
"visit", "vote", 
"wait", "walk", "warn", "wash", "watch", "wear", "will", "win", "wish", 
"wonder", "work", "worry", "write"];

RV:RVCUR:RVIMP[(RV, RV[-1] == e ? RV[0..-2] + ing, RV + d),
               (RV, RV[-1] != e ? RV + ing, RV[-1] != y ? RV + ed),
               (RV, RV[-1] != e ? RV + ing, RV[-1] == y ? RV[0..-2] + ied)];

IV:IVCUR:IVIMP[
("am", "am", "was"), 
("are", "are", "were"),
("is", "is", "was"), 
("be", "being", "been"),
("become", "becoming", "became"),
("begin", "beginning", "began"),
("catch", "catching", "caught"),
("come", "coming", "came"),
("do", "doing", "done"),
("eat","eating", "ate"),
("go", "going", "went"),
("teach", "teaching", "taught")];

# Dunno what this category is called. TOV stands for "That Other Verb-category".;
TOV["could", "do", "would", "just", "simply"];


# ---- Adjectives ---- ;

REGADJ["right","left","back","our", "small", "some", "french", "swedish", "english", "german", "libanese", "gravad"];

ADJMAIN["main"];
ADJPOS["nice", "good", "perfect", "wonderful", "lovely", "splendid", "charming", "tasty", "favorite"];
ADJNEG["allergic", "intolerant"];

# ---- ADVERBS ---- ;

ADV["here","there","nearby","ahead", "then"];

NEG["not", "no"];
POS["yes", "ok", "okay", "okey", "okej", "okidoki", "allright", "allrighty" "yep", "y", "yeah", "sure"];

# ---- Other ---- ;

PRO["you","me","i","it", "he", "she", "we"];

NAME["David","Alex", "Mohammad"];

ARTICLE["the","a","an", "my"];

PREP["to","in","on","near", "with","for", "quite", "today", "of"];

CONJ["and","but"];

DIG["\d+"];

# -----------= Grammar & Semantics =--------------- ;

ART <- ARTICLE;

NOTPHRASE <- NEG<not()> | NEG NEG<nop()>;

NOUN <- REGN <ignore(), REGN> | REGNPL <ignore(), REGNPL:REGN> | 
        IRREGN <ignore(), IRREGN> | IRREGNPL <ignore(), IRREGNPL:IRREGN> | 
        INGR <ingr(), INGR> | INGRPL <ingr(), INGRPL:INGR> |
        ALRG <ingr(),ALRG:INGR> |
        POSREGN<ignore(), POSREGN> | POSREGNPL<ignore(), POSREGNPL:POSREGN> |
        NEGREGN<ignore(), NEGREGN> | NEGREGNPL<ignore(), NEGREGNPL:NEGREGN> |
        SINGLEWORDMEALS <meal(),SINGLEWORDMEALS>;

VERB <- IV<nop()> | IVCUR<nop()> | IVIMP<nop()> | 
        RV<nop()> | RVCUR<nop()> | RVIMP<nop()> | 
        NEGRV<exc()> | NEGRVCUR<exc()> | NEGRVIMP<exc()> | 
        POSRV<inc()> | POSRVCUR<inc()> | POSRVIMP<inc()>;

ADJ <- REGADJ | ADJSTARTER | ADJPOS;



NP <- ALRG NEGREGN <exc(obj(1, ingr(), ALRG:INGR))> | 
      ALRG NEGREGNPL <exc(obj(1, ingr(), ALRG:INGR))> | 
      INGR NEGREGN <exc(obj(1, ingr(), INGR))> | 
      INGR NEGREGNPL <exc(obj(1, ingr(), INGR))> | 
      INGRPL NEGREGN <exc(obj(1, ingr(), INGRPL:INGR))> | 
      INGRPL NEGREGNPL <exc(obj(1, ingr(), INGRPL:INGR))>|
      PRO <obj(1, ignore(), PRO)> | 
      NAME <obj(1, ignore(), NAME)> | 
      NOUN <\nt.nid obj(1, nt, nid)> | 
      ART NOUN <\nt.nid obj(1, nt, nid) > | 
      ART NP | 
      ADJ NOUN <\nt.nid obj(1, nt, nid)> | 
      ADJMAIN NOUN <\nt.nid obj(1, mealcat(), ADJMAIN)> | 
      STARTER <obj(1, mealcat(), STARTER)> | 
      STARTERS <obj(1, mealcat(), STARTERS:STARTER)> | 
      NP PP | DIG NP;

# Special grammatic/semantic rules come first... ;
VP <- VERB ADJNEG PREP ALRG <exc(obj(1, ingr(), ALRG:INGR))> | 
      VERB ADJNEG PREP INGR <exc(obj(1, ingr(), INGR))> | 
      VERB ADJNEG PREP INGRPL <exc(obj(1, ingr(), INGRPL:INGR))>|
      VERB ALRG ADJNEG <exc(obj(1, ingr(), ALRG:INGR))>|
      VERB | VERB POSREGN<inc()> | 
      VERB ART POSREGN<inc()> | 
      VERB NEGREGN<exc()> | 
      VERB ART NEGREGN<exc()> | 
      TOV VP | 
      TOV NOTPHRASE VP NP <\n.f.o+ n(f(o))> | 
      VP NP<\f.o+ f(o)> | 
      VP PP<\f.o+ f(o)> | 
      VP ADV | 
      VERB ADJPOS<inc(obj(1, ignore(), ADJPOS))>;


PP <- PREP NP<\o+ inc(o)> | PREP NEG NP<\o+ exc(o)>
    | PREP VERB ;

# RELCLAUSE <- THAT VP ;

S <- NP VP<\o+.f f(o)> | VP | S CONJ S <\a+.b+.c+ and(a, b, c)> | CONJ S<\a+.b+ and(a, b)> | 
        NP<\o inc(o)> | NEG NP<\o exc(o)> | POS ADV<ok()> | POS <ok()>;

\end{verbatim}